define(['plugins/router', 'knockout', 'durandal/system'], function (router, ko, system) {
    var masterVm = ko.observable();

    var childRouter = router
        .createChildRouter()
        .makeRelative({ moduleId: 'keyedMasterDetail', fromParent: true, dynamicHash: ':resourceId' })
        .map([
            { route: ['news', ''], moduleId: 'news/news', title: '新闻', nav: true, hash: '#news' },
            { route: 'videos', moduleId: 'videos/videos', title: '电影', nav: true },
            { route: 'sports', moduleId: 'sports/sports', title: '体育', nav: true }
        ]).buildNavigationModel();

    var vm = {
        router: childRouter,
        activate: activate,
        deactivate: deactivate,
        masterVm: masterVm
    };

    return vm;

    function activate(resourceId,...args) {
        system.log('主视图' + resourceId + ' 已激活');
        return loadObservables(resourceId);
    }

    function deactivate() {
        system.log('主视图 ' + masterVm().id + ' 已取消激活');
    }

    function loadObservables(id) {
        console.log("加载监控");
        masterVm({
            id: id,
            name: '资讯'
        });
    }
});